package er;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class NumberTwelve {
    public static void main(String[] args) {
        File file=new File("G:/V2/day10-IO流（二）/IO资源路径");
        File copfile=new File("G:/file/img");
        File[] files = file.listFiles(file1-> file1.getName().toLowerCase().endsWith(".jpeg"));
        //File[] files = file.listFiles((d, name) -> new File(d, name).isDirectory() || name.toLowerCase().endsWith(".jpeg"));
        for (File file1 : files) {
            cop(file1,copfile,file1.getName());
        }


    }
    public static void cop(File file,File file1,String name){
        try(
                FileInputStream fileInputStream=new FileInputStream(file);
                FileOutputStream fileOutputStream=new FileOutputStream(new File(file1,name));
        ) {
            byte[] bytes=new byte[1024];
            int len=-1;
            while((len=fileInputStream.read(bytes))!=-1){
                fileOutputStream.write(bytes,0,len);
            }
        }catch (IOException e){
            e.printStackTrace();
        }

    }
}
